const xlsx = require("node-xlsx");
const path = require("path");
const uuid = require("uuid");
const md5 = require("md5");

const user = require("../User");
const job = require("../Job");
const team = require("../Team");

async function fn(){
  const jobData = await job.find({},{_id:0, __v:0});
  const teamData = await team.find({},{_id:0, __v:0});
  // 导入用户
  const data = xlsx.parse(path.join( __dirname, "..", "..", "xlsx", "user.xlsx" ))[0].data;

  const arr = [];
  for(let i=1; i<data.length-1; i++){
    arr.push({
      uId: 'user-'+uuid.v1(),     // 唯一标志
      employeesName: data[i][0],  // 姓名
      job: jobData.find( v=>v.jName===data[i][1] ),       // 职务
      team: teamData.filter( v=>v.tName===data[i][2] ),   // 部门
      password: md5('123456'),// 密码
      regTime: Date.now(),    // 注册时间
      power: ['/order', '/order/search', '/order/add', '/order/setUser', '/order/exportTemp', '/order/export', '/', '/dashboard', '/dashboard/getData', '/setpassword', '/setpassword/set', '/customer', '/customer/add', '/customer/set', '/customer/delete']
    })
  }
  user.insertMany( arr ).then(()=>{
    console.log('用户导入成功')
  })
}
fn()

